#include"ContactsClient.hpp"





void menu()
{
    std::cout << "-----------------------------------------------------" << std::endl
    << "--------------- 请选择对通讯录的操作 ----------------" << std::endl
     << "------------------ 1、新增联系⼈ --------------------" << std::endl
     << "------------------ 2、删除联系⼈ --------------------" << std::endl
     << "------------------ 3、查看联系⼈列表 ----------------" << std::endl
     << "------------------ 4、查看联系⼈详细信息 ------------" << std::endl
     << "------------------ 0、退出 --------------------------" << std::endl
     << "-----------------------------------------------------" << std::endl;

}

int main(int argc, char* argv[])
{
    if(argc != 3)
    {
        cout << "Usage: " << argv[0] << " <server_ip> <server_port>" << endl;
        return 1;
    }

    enum OPTION {EXIT = 0, ADD, DEL, FIND_ALL, FIND_ONE};
    ContactsClient contacts_client;
    while(true)
    {
        menu();
        cout << "请输入选项：";
        int choice;
        cin >> choice;
        cin.ignore(256,'\n');
        try
        {
            switch(choice)
            {
                case OPTION::EXIT:
                    cout << "退出程序" << endl;
                    return 0;
                case OPTION::ADD:
                    contacts_client.addContact(argv[1], argv[2]);
                    break;
                case OPTION::DEL:
                    contacts_client.deleteContact(argv[1], argv[2]);
                    break;
                case OPTION::FIND_ALL:
                    contacts_client.findContacts(argv[1], argv[2]); 
                    break;  
                case OPTION::FIND_ONE:
                    contacts_client.findContact(argv[1], argv[2]);
                    break;
                default:
                    cout << "输入error，请重新输入" << endl;
                    break;
            }
        }catch(const ContactException& e)
        {
            std::cerr << "---> 操作通讯录时发现异常！！！" << std::endl
                        << "---> 异常信息：" << e.what() << std::endl;
        }
    }
    return 0;
}

